package com.example.sourcecodelearning.proxy.factory;

import net.sf.cglib.proxy.Enhancer;

public class CglibProxyFactory {

    @SuppressWarnings("unchecked")
    public static <T> T newProxyInstance(Object target) {
        // 实例化增强器
        Enhancer enhancer = new Enhancer();
        // 设置目标类
        enhancer.setSuperclass(target.getClass());
        // 设置回调的实现类即代理对象
        enhancer.setCallback(new CglibProxy());
        return (T) enhancer.create();
    }

}
